package com.example.bishe.mapper;

import com.example.bishe.entity.Zsj_bzks;
import com.example.bishe.entity.Zsj_jzg;
import com.example.bishe.service.impl.Zsj_bzksServiceImpl;
import com.example.bishe.service.impl.Zsj_jzgServiceImpl;
import com.example.bishe.toolclass.StringTurnJson;
import net.sourceforge.pinyin4j.PinyinHelper;
import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType;
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

/**
 * @Author yws
 * @Date 2022/3/21 14:45
 */
@SpringBootTest
public class HanPinYin {
    @Test
    public String getPinyin(String china) {
        HanyuPinyinOutputFormat formart = new HanyuPinyinOutputFormat();
        formart.setCaseType(HanyuPinyinCaseType.LOWERCASE);
        formart.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
        formart.setVCharType(HanyuPinyinVCharType.WITH_V);
        char[] arrays = china.trim().toCharArray();
        String result = "";
        try {
            for (int i=0;i<arrays.length;i++) {
                char ti = arrays[i];
                if(Character.toString(ti).matches("[\\u4e00-\\u9fa5]")){ //匹配是否是中文
                    String[] temp = PinyinHelper.toHanyuPinyinStringArray(ti,formart);
                    result += temp[0];
                }else{
                    result += ti;
                }
            }
        } catch (BadHanyuPinyinOutputFormatCombination e) {
            e.printStackTrace();
        }
        return result;
    }

    @Autowired
    Zsj_bzksServiceImpl zs;
    @Autowired
    StringTurnJson st;
    @Autowired
    Zsj_jzgServiceImpl jzg;
    @Test
    public void update(){
       /* Zsj_bzks[] zsj_bzks = zs.selectAll1();
        for (int i = 0; i < zsj_bzks.length; i++) {
            String pinyin = st.getPinyin(zsj_bzks[i].getXm());
            zsj_bzks[i].setEmail(pinyin);
            zs.queryOne(zsj_bzks[i]);
        }*/
       /* Zsj_jzg[] zsj_jzgs = jzg.selectAll();
        for (int i = 0; i < zsj_jzgs.length; i++) {
            String pinyin = st.getPinyin(zsj_jzgs[i].getXm());
            zsj_jzgs[i].setEmail(pinyin);
            jzg.queryOne(zsj_jzgs[i]);
        }*/
    }

}
